<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 将用户输入的网址转换成官网
    // www.baidu.com -- www.lagou.com


    function testReg() {
      var input = prompt("请输入一个网址");
      var str = "lagou";
      var reg = /^(w{3}\.{1})([0-z]+)(\.{1}com)$/;
      var str1 = input.replace(reg, function (match, $1, $2, $3) {
        return $1 + str + $3;
      });
      alert(str1);
    }

    testReg();



  </script>
</body>

</html>